macroquad
macroquad
is a simple and easy to use game library for Rust programming language, heavily inspired by raylib.
Features
- Same code for all supported platforms, no platform dependent defines required.
- Efficient 2D rendering with automatic geometry batching.
- Minimal amount of dependencies: build after
cargo clean
takes only 16s on x230(~6 years old laptop). - Immediate mode UI library included.
- Single command deploy for both WASM and Android build instructions.
Supported Platforms
- PC: Windows/Linux/macOS;
- HTML5;
- Android;
- IOS.
Build Instructions
Setting Up a Macroquad Project
Macroquad is a normal rust dependency, therefore an empty macroquad project may be created with:
# Create empty cargo project
Add macroquad as a dependency to Cargo.toml:
[]
= "0.4"
Put some macroquad code in src/main.rs
:
use *;
async
And to run it natively:
For more examples take a look at Macroquad examples folder
Linux
# ubuntu system dependencies
# fedora system dependencies
# arch linux system dependencies
Windows
On windows both MSVC and GNU target are supported, no additional dependencies required.
Also cross-compilation to windows from linux is supported:
WASM
This will produce .wasm file in target/debug/wasm32-unknown-unknown/CRATENAME.wasm
or in target/release/wasm32-unknown-unknown/CRATENAME.wasm
if built with --release
.
And then use the following .html to load it:
<!-- Minified and statically hosted version of https://github.com/not-fl3/macroquad/blob/master/js/mq_js_bundle.js -->
<!-- Your compiled wasm file -->
TITLE
One of the ways to server static .wasm and .html:
IOS
To run on the simulator:
mkdir MyGame.app
cargo build --target x86_64-apple-ios --release
cp target/release/mygame MyGame.app
# only if the game have any assets
cp -r assets MyGame.app
cat > MyGame.app/Info.plist << EOF
CFBundleExecutable
mygame
CFBundleIdentifier
com.mygame
CFBundleName
mygame
CFBundleVersion
1
CFBundleShortVersionString
1.0
EOF
xcrun simctl install booted MyGame.app/
xcrun simctl launch booted com.mygame
For details and instructions on provisioning for real iphone, check https://macroquad.rs/articles/ios/
[]
= 3
async/await
While macroquad attempts to use as few Rust-specific concepts as possible, .await
in all examples looks a bit scary.
Rust's async/await
is used to solve just one problem - cross platform main loop organization.
The problem: on WASM and android it's not really easy to organize the main loop like this:
fn main() {
// do some initialization
// start main loop
loop {
// handle input
// update logic
// draw frame
}
}
It is fixable on Android with threads, but on web there is not way to "pause" and "resume" WASM execution, so no WASM code should block ever. While that loop is blocking for the entire game execution! The C++ solution for that problem: https://kripken.github.io/blog/wasm/2019/07/16/asyncify.html
But in Rust we have async/await. Rust's futures
are basically continuations - future
's stack may be stored into a variable to pause/resume execution of future's code at a later point.
async/await support in macroquad comes without any external dependencies - no runtime, no executors and futures-rs is not involved. It's just a way to preserve main
's stack on WASM and keep the code cross platform without any WASM-specific main loop.
Community
- Quads Discord server - a place to chat with the library's devs and other community members.
- Awesome Quads - a curated list of links to miniquad/macroquad-related code & resources.
Platinum sponsors
Macroquad is supported by: